package auction.serveroutage;


import java.io.IOException;
import java.net.Socket;
import java.net.UnknownHostException;


import org.apache.log4j.Logger;

import auction.client.Client;

public class ClientReconnectThread  extends Thread{
	public static Logger log = Logger.getLogger(ClientReconnectThread.class);
	
	private String serverHost;
	private int serverPort;
	private Socket serverSocket;
	
	public ClientReconnectThread(String serverHost, int serverPort) {
		this.serverHost = serverHost;
		this.serverPort = serverPort;
	}
	
	public void run() {
		while(!Client.isEnded()){
			
			try {
				synchronized(this){
				this.wait(500);
				}
			} catch (InterruptedException e1) {
				
			}
			
			try {
				serverSocket = new Socket(serverHost, serverPort);
				Client.setServerSocket(serverSocket);
				Client.reconnect();
				break;
			} catch (UnknownHostException e) {
				continue;
			} catch (IOException e) {
				continue;
			}
			
		}
	}
}

